C       GEMPACK Software System                     Impact Project
C       -----------------------                     --------------
C
	SUBROUTINE HAHMA( filun, numar,
     *    ERRMES)
C
C   ACRONYM
C   -------
C
C Header Array file: How Many Arrays on it?
C H      A           H   M    A
C
C       COPYRIGHT 1995: The Impact Project and KPSOFT
C
C   DESCRIPTION
C   -----------
C
C       This counts the number of arrays on a HA file.
C
C   CURRENT VERSION
C   ---------------
C
C       Version 1               February 1995
C
C   HISTORY
C   -------
C
C   Date           Author(s)            Comments
C   --------------------------------------------------------------
C   13/02/95       Ken Pearson          Version 1
C
C   NOTES
C   -----
C
 
C
C   FINE PRINT
C   ----------
C
C       - All variables and arrays are explicitly declared. None
C         are implicit.
C
C   SUBROUTINE VARIABLES
C   --------------------
C
C   (1) INPUT VARIABLES (NOT ALTERED):
C
C       FILUN - unit number of the HA file
C
	integer filun
C
C   (2) OUTPUT VARIABLES (RETURNED):
C
C       NUMAR - number of arrays found
C
	integer numar
C
C   (3) INPUT/OUTPUT VARIABLES:
C
C       ERRMES - Contains fatal error messages if ERRMES(1:1)='E'
C
	CHARACTER*(*)   ERRMES
C
C   SIGNIFICANT PARAMETERS
C   ----------------------
C
C       SUBNAM - The name of this subroutine
C
	CHARACTER*6     SUBNAM
	PARAMETER       (SUBNAM='HAHMA')
C
C   ERROR CHECKING AND HANDLING
C   ---------------------------
C
C       A fatal error (ERRMES(1:1)='E') results if:
 
C
C   SUBROUTINES AND FUNCTIONS CALLED
C   --------------------------------
C
	EXTERNAL GPPGER, PERET, PERETM
C
C       **********************************************************
C
C       End of subroutine documentation
C
C       **********************************************************
C
C   LOCAL VARIABLES
C   ---------------
C
	character*4 tfilpb
	integer ios
C
C   IMPORTANT STATEMENT LABELS
C   --------------------------
C
C       15000   15300   15500   Error return for orderly stop
C       23700   Trap for file-read errors
C
C       **********************************************************
C
C       Subroutine begins
C
C       **********************************************************
C
	call GPREW( filun, errmes)
	if( errmes(1:1).eq.'E') goto 15000
	write(*,*)'HAHMA. ERRMES=', errmes
C
	numar=0
C
100     continue
	read(unit=filun, end=200, err=23700, iostat=ios) tfilpb
	write(*,*)'HAHMA. TFILPB=', tfilpb
	if(tfilpb.ne.' ') then
	  numar=numar+1
	end if
C
	goto 100
C
200     continue
	write(*,*)'HAHMA. EOF found. IOS=', ios
	if(ios.ne.0) then
	  call GPTIOS(ios)
	end if
C
C       Normal return
C       -------------
C
	RETURN
C
C       Error RETURN for orderly stop
C       -----------------------------
C
15000   CONTINUE
	CALL PERET (SUBNAM)
	RETURN
C
C   (Program error)
C
C15300  CONTINUE
C       CALL GPPGER( 0, ERRMES)
C       GOTO 15500
C
15500   CONTINUE
	CALL PERETM (SUBNAM, ERRMES)
	RETURN
C
C       Trap for READ errors from files other than unit *
C       -------------------------------------------------
C
23700   CONTINUE
	call GPTO2(
     *    '\n  **STOP since error during read from unit number %i.',
     *    '\n     (IOSTAT value is %i.)',
     *    ' ',' ',filun,ios, errmes)
	if( errmes(1:1).eq.'E') goto 15000
	ERRMES =        'E--READ ERROR'
	GOTO 15500
C
	END
